package org.shangrila.app.sys.shiro;

import java.util.List;

import org.shangrila.app.sys.eo.SysAuthority;
import org.shangrila.app.sys.eo.SysRole;
import org.shangrila.app.sys.eo.SysUser;
import org.shangrila.comm.dao.DbAccess;


public class Test {

	public static void main(String[] args) {
		
		//System.out.println("OK");
		//B();
		//C();
		D("shangrila","shangrila");
	}
	
	public static void D(String username,String password) {
		DbAccess db = new DbAccess();
		SysUser user = (SysUser) db.createNamedQuery("SysUser.findByUsernoPassword").setParameter(1, username).setParameter(2, password).getSingleResult();
			System.out.println(user.getUserno()+"--"+user.getUsername());			
			for(SysRole r:user.getSysRoles()) {
				System.out.println("-------");
				System.out.println("SysRole:"+r.getDescription()+"--"+r.getName());					
				for(SysAuthority a:r.getSysAuthorities()){
					System.out.println("SysAuthorities:"+a.getDescription()+"--"+a.getName());	
				}
			}
	
		}

	public static void C() {
		DbAccess db = new DbAccess();
		@SuppressWarnings("unchecked")
		List<SysRole> roles = (List<SysRole>) db.createNamedQuery("SysRole.findAll").getResultList();
		System.out.println(roles.size());
		for(SysRole s : roles) { 
			System.out.println(s.getDescription()+"--"+s.getName());			 
			for(int i=0;i<s.getSysAuthorities().size();i++) {
				SysAuthority a = s.getSysAuthorities().get(i); 
				System.out.println("SysRole:"+s.getDescription()+"--"+a.getDescription()+"--"+a.getName());
				
			}}
		
	}


}
